package com.happy.ibidding.service;

import com.happy.ibidding.dao.FileRepository;
import com.happy.ibidding.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.OutputStream;


@Service
public class FileService {

    @Autowired
    private FileRepository fileRepository;

    public File getFile(String imageId) throws Exception {
        return fileRepository.readFile(imageId);
    }

    public String saveFile(byte[] fileBytes, String fileName) throws Exception {
        //生成文件号
        String fileId = RandomUtil.generateRandomId("file_", fileName);
        //保存
        fileRepository.saveImage(fileBytes, fileId);
        return fileId;
    }
}